{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "better-invitation",
   "metadata": {},
   "source": [
    "# Problem 14.16 Compressor Duty and State Properties after Ammonia Compression"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "charged-october",
   "metadata": {},
   "source": [
    "Ammonia at 100  °C and 5 bar is compressed to a pressure of 10 bar. The thermal efficiency of the process is 0.8; and the mechanical efficiency is 0.9. What is the compressor duty per mole and the temperature of the outlet?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "canadian-reservoir",
   "metadata": {},
   "source": [
    "## Solution \n",
    "\n",
    "This is just another compression problem."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "typical-october",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The actual power is 3149 W/mol\n",
      "The actual outlet temperature is  448.32 K\n"
     ]
    }
   ],
   "source": [
    "# Set the conditions and imports\n",
    "from scipy.constants import bar\n",
    "from thermo import ChemicalConstantsPackage, PRMIX, CEOSLiquid, CEOSGas, FlashPureVLS\n",
    "fluid = 'ammonia'\n",
    "constants, correlations = ChemicalConstantsPackage.from_IDs([fluid])\n",
    "\n",
    "T1 = 100 + 273.15\n",
    "P1 = 5*bar\n",
    "P2 = 10*bar\n",
    "zs = [1]\n",
    "\n",
    "eta_isentropic = 0.8\n",
    "eta_mechanical = 0.9\n",
    "\n",
    "eos_kwargs = dict(Tcs=constants.Tcs, Pcs=constants.Pcs, omegas=constants.omegas)\n",
    "liquid = CEOSLiquid(PRMIX, HeatCapacityGases=correlations.HeatCapacityGases,\n",
    "                    eos_kwargs=eos_kwargs)\n",
    "gas = CEOSGas(PRMIX, HeatCapacityGases=correlations.HeatCapacityGases, \n",
    "              eos_kwargs=eos_kwargs)\n",
    "flasher = FlashPureVLS(constants, correlations, liquids=[liquid], gas=gas, solids=[])\n",
    "\n",
    "state_1 = flasher.flash(T=T1, P=P1)\n",
    "state_2_ideal = flasher.flash(S=state_1.S(), P=P2)\n",
    "# Compute the change in enthalpy\n",
    "delta_H_ideal = (state_2_ideal.H()-state_1.H())\n",
    "H_added_to_fluid_actual = delta_H_ideal/eta_isentropic\n",
    "\n",
    "state_2 = flasher.flash(H=state_1.H() + H_added_to_fluid_actual, P=P2)\n",
    "\n",
    "specific_power = (state_2.H() - state_1.H())/(eta_mechanical)\n",
    "print(f'The actual power is {specific_power:.0f} W/mol')\n",
    "print(f'The actual outlet temperature is {state_2.T: .2f} K')"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
